package de.koller.worlders.engine.entity.deco;

import de.koller.worlders.WorldersRoot;
import de.koller.worlders.engine.tiles.ITile;
import de.koller.worlders.engine.tiles.data.ITileCreator;
import de.koller.worlders.engine.tiles.light.LightSource;
import de.koller.worlders.render.VisualMap;
import de.koller.worlders.render.visual.DisplayRenderObject;

public class Torch extends Deco {
	public static final int GEN_ID = 4;
	
	private LightSource lightSource;
	
	public static final ITileCreator GEN_INSTANCE = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Torch();
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.torch; }
		@Override public String getName() { return "Fackel"; }
	};

	public Torch() {
		super( .2f );
	}

	@Override
	public void generate( WorldersRoot root, Object... references ) {
		super.generate( root, references );
		
		this.setVisual( VisualMap.torch );
		
		if( this.getTile() == null )
			return;
		
		lightSource = root.getTileMap().getLight().addLightSource( 
				this.getTile().getPosition().getXi(), this.getTile().getPosition().getYi(), 0xffc0842b );
	}

	@Override
	public void ungenerate() {
		super.ungenerate();
		
		root.getTileMap().getLight().removeLightSource( lightSource );
	}

}